home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / RIPDUMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-28  |  2.4 KB  |  103 lines

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *  Changes Copyright (c) 1993 Jeff White - N0POY, All Rights Reserved.
  5.  *  Permission granted for non-commercial copying and use, provided
  6.  *  this notice is retained.
  7.  *
  8.  * Rehack for RIP-2 (RFC1388) by N0POY 4/1993
  9.  *
  10.  * Beta release 11/10/93 V0.91
  11.  *
  12.  * 2/19/94 release V1.0
  13.  *
  14.  *
  15.  * Tracing to sockets, mods April '95 by Johan. K. Reinalda, WG7J
  16.  *
  17.  * Rip98 support added, G4HIP - 29/3/97
  18.  */
  19.  
  20. #include "global.h"
  21. #ifdef RIP
  22. #include "mbuf.h"
  23. #include "netuser.h"
  24. #include "rip.h"
  25. #include "trace.h"
  26.  
  27.   
  28. #if !defined(_lint)
  29. static char rcsid[] OPTIONAL = "$Id: ripdump.c,v 1.12 1997/06/28 16:46:13 root Exp root $";
  30. #endif
  31.  
  32. void
  33. rip_dump(fp,bpp)
  34. FILE *fp;
  35. struct mbuf **bpp;
  36. {
  37. struct rip_route entry;
  38. struct rip_authenticate *ripauth;
  39. int i;
  40. int cmd, version;
  41. int16 len = 0;
  42. int entrylen = RIP_ENTRY;   
  43. int16 domain;
  44. char ipaddmask[25];
  45.   
  46.     traceprintf (fp, "RIP: ");
  47.     cmd = PULLCHAR(bpp);
  48.     version = PULLCHAR(bpp);
  49.     switch (cmd)    {
  50.         case RIPCMD_REQUEST:    traceprintf (fp, "REQUEST");
  51.                     break;
  52.         case RIPCMD_RESPONSE:    traceprintf (fp, "RESPONSE");
  53.                     break;
  54.         default:        traceprintf (fp, " cmd %u", cmd);
  55.                     break;
  56.     }
  57.   
  58.     domain = pull16 (bpp);
  59.   
  60.     if (bpp)
  61.         len = len_p (*bpp);
  62.     traceprintf (fp, " vers %u entries %u domain %u:\n", version, len / RIP_ENTRY, domain);
  63.   
  64.     i = 0;
  65.     if (version == RIP_VERSION_98)
  66.         entrylen = RIP98_ENTRY;
  67.     while (len >= entrylen)    {
  68.         /* Pull an entry off the packet */
  69.             if (version != RIP_VERSION_98)
  70.                     pullentry (&entry, bpp);
  71.             else
  72.                     pull98entry (&entry,bpp);
  73.             len -= (int16) entrylen;
  74.   
  75.         if (entry.rip_family == RIP_AF_AUTH) {
  76.             ripauth = (struct rip_authenticate *)&entry;
  77.             traceprintf (fp, "RIP: AUTHENTICATION Type %d  Password: %.16s\n",
  78.                 ripauth->rip_auth_type, ripauth->rip_auth_str);
  79.             continue;
  80.         }
  81.   
  82.         if (entry.rip_family != RIP_AF_INET) {
  83.             /* Skip non-IP addresses */
  84.             continue;
  85.         }
  86.   
  87.         if (version >= RIP_VERSION_2) {
  88.             sprintf (ipaddmask, "%s/%-4d", inet_ntoa (entry.rip_dest),
  89.             mask2width (entry.rip_dest_mask));
  90.         } else
  91.             sprintf (ipaddmask, "%s/??", inet_ntoa (entry.rip_dest));
  92.         traceprintf (fp, "%-20s%-3lu", ipaddmask, entry.rip_metric);
  93.   
  94.         if ((++i % 3) == 0)
  95.             traceprintf (fp, "\n");
  96.     }
  97.     if((i % 3) != 0)
  98.         traceprintf (fp, "\n");
  99. }
  100.   
  101. #endif /* RIP */
  102.   
  103.